<template>
  <selectFarm @farmtypemessage="farmtypemessage">
    <template v-slot:farmtypemain>
      <div style="display:flex;align-items: center;margin-bottom: 10px;">
        <span>状态：</span>
        <el-checkbox-group
          v-model="facilityArr"
          @change="facilityType"
        >
          <el-checkbox-button
            v-for="(city, index) in facilityTypeList"
            :key="index"
            :label="city.status"
          >{{ city.name }}
          </el-checkbox-button>
        </el-checkbox-group>
      </div>
      <div v-if="typeNo === 'unit'" style="height: 100%">
        <el-table
          v-loading="loading"
          highlight-current-row
          :data="ExamineTable"
          stripe
          border
          height="calc(100% - 90px)"
        >
          <el-table-column type="index" label="序号" width="100" />
          <el-table-column prop="organizationName" label="基地" />
          <el-table-column prop="unitName" label="单位名称" />
          <el-table-column prop="symbol" label="单位符号" />
          <el-table-column prop="reason" label="原因">
            <template slot-scope="scope">
              {{ scope.row.reason || '————' }}
            </template>
          </el-table-column>
          <el-table-column prop="applyStatus" label="状态">
            <template slot-scope="scope">
              <el-button v-if="scope.row.applyStatus === 1" style="color:aqua" class="text-btn-cursor" type="text" size="small" @click="handlecheck(scope.row)">
                <i class="el-icon-check"></i> 通过</el-button>
              <el-button v-if="scope.row.applyStatus === 1" class="text-btn-cursor cursor-delete" type="text" size="small" @click="handleclose(scope.row)">
                <i class="el-icon-close"></i> 不通过</el-button>
              <span v-if="scope.row.applyStatus === 0" style="color: green;font-weight: 600;"> 通过</span>
              <span v-if="scope.row.applyStatus === 2" style="color: red;font-weight: 600;"> 审核不通过</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div v-if="typeNo === 'unitType'" style="height: 100%">
        <el-table
          v-loading="loading"
          highlight-current-row
          :data="ExamineTable"
          stripe
          border
          height="calc(100% - 90px)"
        >
          <el-table-column type="index" label="序号" width="100" />
          <el-table-column prop="organizationName" label="基地" />
          <el-table-column prop="unitTypeName" label="单位类型名称" />
          <el-table-column prop="reason" label="原因">
            <template slot-scope="scope">
              {{ scope.row.reason || '————' }}
            </template>
          </el-table-column>
          <el-table-column prop="applyStatus" label="状态">
            <template slot-scope="scope">
              <el-button v-if="scope.row.applyStatus === 1" style="color:aqua" class="text-btn-cursor" type="text" size="small" @click="handlecheck(scope.row)">
                <i class="el-icon-check"></i> 通过</el-button>
              <el-button v-if="scope.row.applyStatus === 1" class="text-btn-cursor cursor-delete" type="text" size="small" @click="handleclose(scope.row)">
                <i class="el-icon-close"></i> 不通过</el-button>
              <span v-if="scope.row.applyStatus === 0" style="color: green;font-weight: 600;"> 通过</span>
              <span v-if="scope.row.applyStatus === 2" style="color: red;font-weight: 600;"> 审核不通过</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div v-if="typeNo === 'variety'" style="height: 100%">
        <el-table
          v-loading="loading"
          highlight-current-row
          :data="ExamineTable"
          stripe
          border
          height="calc(100% - 90px)"
        >
          <el-table-column type="index" label="序号" width="100" />
          <el-table-column prop="organizationName" label="基地" />
          <el-table-column prop="plantVarietyName" label="种养品种名称" />
          <el-table-column prop="plantTypeName" label="种养类别">
            <template slot-scope="scope">
              {{ scope.row.plantTypeName || '————' }}
            </template>
          </el-table-column>
          <el-table-column
            prop="description"
            label="最佳种养时间"
          >
            <template slot-scope="scope">
              {{ scope.row.sowingStartDate }} <span v-if="scope.row.sowingStartDate&&scope.row.sowingEndDate">
                ~
              </span>{{ scope.row.sowingEndDate }}
            </template>
          </el-table-column>
          <el-table-column prop="reason" label="原因">
            <template slot-scope="scope">
              {{ scope.row.reason || '————' }}
            </template>
          </el-table-column>
          <el-table-column prop="applyStatus" label="状态">
            <template slot-scope="scope">
              <el-button v-if="scope.row.applyStatus === 1" style="color:aqua" class="text-btn-cursor" type="text" size="small" @click="handlecheck(scope.row)">
                <i class="el-icon-check"></i> 通过</el-button>
              <el-button v-if="scope.row.applyStatus === 1" class="text-btn-cursor cursor-delete" type="text" size="small" @click="handleclose(scope.row)">
                <i class="el-icon-close"></i> 不通过</el-button>
              <span v-if="scope.row.applyStatus === 0" style="color: green;font-weight: 600;"> 通过</span>
              <span v-if="scope.row.applyStatus === 2" style="color: red;font-weight: 600;"> 审核不通过</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div v-if="typeNo === 'category'" style="height: 100%">
        <el-table
          v-loading="loading"
          highlight-current-row
          :data="ExamineTable"
          stripe
          border
          height="calc(100% - 90px)"
        >
          <el-table-column type="index" label="序号" width="100" />
          <el-table-column prop="organizationName" label="基地" />
          <el-table-column prop="parentName" label="归属" />
          <el-table-column prop="plantTypeName" label="种养类别">
            <template slot-scope="scope">
              {{ scope.row.plantTypeName || '————' }}
            </template>
          </el-table-column>
          <el-table-column prop="reason" label="原因">
            <template slot-scope="scope">
              {{ scope.row.reason || '————' }}
            </template>
          </el-table-column>
          <el-table-column prop="applyStatus" label="状态">
            <template slot-scope="scope">
              <el-button v-if="scope.row.applyStatus === 1" style="color:aqua" class="text-btn-cursor" type="text" size="small" @click="handlecheck(scope.row)">
                <i class="el-icon-check"></i> 通过</el-button>
              <el-button v-if="scope.row.applyStatus === 1" class="text-btn-cursor cursor-delete" type="text" size="small" @click="handleclose(scope.row)">
                <i class="el-icon-close"></i> 不通过</el-button>
              <span v-if="scope.row.applyStatus === 0" style="color: green;font-weight: 600;"> 通过</span>
              <span v-if="scope.row.applyStatus === 2" style="color: red;font-weight: 600;"> 审核不通过</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div v-if="typeNo === 'material'" style="height: 100%">
        <el-table
          v-loading="loading"
          highlight-current-row
          :data="ExamineTable"
          stripe
          border
          height="calc(100% - 90px)"
        >
          <el-table-column type="index" label="序号" width="100" />
          <el-table-column prop="organizationName" label="基地" />
          <el-table-column
            prop="materialName"
            label="物料名称"
          />
          <el-table-column
            prop="materialTypeName"
            label="物料类型"
          >
            <template slot-scope="scope">
              {{ scope.row.materialTypeName || '————' }}
            </template>
          </el-table-column>
          <el-table-column
            prop="description"
            label="规格"
          >
            <template slot-scope="scope">
              {{ scope.row.specification }} {{ scope.row.perSpecUnitName }}  <span v-if="scope.row.perSpecUnitName&&scope.row.unitName">
                /
              </span> {{ scope.row.unitName }}
            </template>
          </el-table-column>
          <el-table-column
            prop="description"
            label="定额定量"
          >
            <template slot-scope="scope">
              {{ scope.row.ratedQuantity }} {{ scope.row.perSpecUnitName }}  <span v-if="scope.row.perSpecUnitName&&scope.row.areaUnitName">
                /
              </span> {{ scope.row.areaUnitName }}
            </template>
          </el-table-column>
          <el-table-column prop="reason" label="原因">
            <template slot-scope="scope">
              {{ scope.row.reason || '————' }}
            </template>
          </el-table-column>
          <el-table-column prop="applyStatus" label="状态">
            <template slot-scope="scope">
              <el-button v-if="scope.row.applyStatus === 1" style="color:aqua" class="text-btn-cursor" type="text" size="small" @click="handlecheck(scope.row)">
                <i class="el-icon-check"></i> 通过</el-button>
              <el-button v-if="scope.row.applyStatus === 1" class="text-btn-cursor cursor-delete" type="text" size="small" @click="handleclose(scope.row)">
                <i class="el-icon-close"></i> 不通过</el-button>
              <span v-if="scope.row.applyStatus === 0" style="color: green;font-weight: 600;"> 通过</span>
              <span v-if="scope.row.applyStatus === 2" style="color: red;font-weight: 600;"> 审核不通过</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div v-if="typeNo === 'materialType'" style="height: 100%">
        <el-table
          v-loading="loading"
          highlight-current-row
          :data="ExamineTable"
          stripe
          border
          height="calc(100% - 90px)"
        >
          <el-table-column type="index" label="序号" width="100" />
          <el-table-column prop="organizationName" label="基地" />
          <el-table-column prop="parentName" label="归属" />
          <el-table-column prop="materialTypeName" label="农资类型">
            <template slot-scope="scope">
              {{ scope.row.materialTypeName || '————' }}
            </template>
          </el-table-column>
          <el-table-column prop="reason" label="原因">
            <template slot-scope="scope">
              {{ scope.row.reason || '————' }}
            </template>
          </el-table-column>
          <el-table-column prop="applyStatus" label="状态">
            <template slot-scope="scope">
              <el-button v-if="scope.row.applyStatus === 1" style="color:aqua" class="text-btn-cursor" type="text" size="small" @click="handlecheck(scope.row)">
                <i class="el-icon-check"></i> 通过</el-button>
              <el-button v-if="scope.row.applyStatus === 1" class="text-btn-cursor cursor-delete" type="text" size="small" @click="handleclose(scope.row)">
                <i class="el-icon-close"></i> 不通过</el-button>
              <span v-if="scope.row.applyStatus === 0" style="color: green;font-weight: 600;"> 通过</span>
              <span v-if="scope.row.applyStatus === 2" style="color: red;font-weight: 600;"> 审核不通过</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <Pagination
        :page-size="pageSize"
        :current-page="currentPage"
        :total-size="totalSize"
        @changePageSize="changePageSize"
        @changeCurrentPage="changeCurrentPage"
      />
      <el-dialog
        :title="'原因'"
        class="formData"
        :visible.sync="dialogExamineFormVisible"
        width="50%"
        top="15vh"
        :before-close="close"
      >
        <el-form
          ref="ExamineForm"
          label-position="left"
          :model="ExamineForm"
          class="el-form"
        >
          <!--
            :rules="[{
              message: '原因不能为空',
              trigger: 'blur',
              required: true
            }]" -->
          <el-form-item
            label="原因:"
            prop="reason"
            class="w100p"
          >
            <el-input v-model="ExamineForm.reason" clearable type="textarea" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button class="zh-button-one" @click="close">关 闭</el-button>
          <el-button class="zh-button-two" type="primary" @click="savemes">保 存</el-button>
        </div>
      </el-dialog>
    </template>
  </selectFarm>
</template>

<script>
import selectFarm from "./selectFarm";
import Pagination from "@/components/Pagination";
import Axios from "axios";
import { mymixin } from "@/utils/mixins";
export default {
  components: {
    selectFarm,
    Pagination
  },
  mixins: [mymixin],
  data() {
    return {
      typeNo: "unit",
      ExamineTable: [],
      pageSize: 10,
      currentPage: 1,
      totalSize: 0,
      // ---添加相关---
      diastau: 0,
      facilityTypeList: [
        {
          status: 0,
          name: '通过'
        },
        {
          status: 1,
          name: '待审核'
        },
        {
          status: 2,
          name: '审核不通过'
        }
      ],
      dialogExamineFormVisible: false,
      applyStatus: '',
      ExamineForm: {},
      facilityArr: []
    };
  },
  methods: {
    farmtypemessage(e) {
      this.typeNo = e.typeNo;
      this.gettabledataList()
    },
    close() {
      this.dialogExamineFormVisible = false
    },
    facilityType(e) {
      if (e.length > 0) {
        this.facilityArr = e.splice(-1)
        this.applyStatus = this.facilityArr[0]
        // console.log(this.applyStatus)
        this.gettabledataList()
      } else {
        this.applyStatus = ''
        this.gettabledataList()
      }
    },
    // 获取表格信息
    async gettabledataList() {
      this.loading = true
      let params = {
        page: this.currentPage,
        size: this.pageSize,
        entity: {
          applyStatus: this.applyStatus
        }
      }
      let url = ''
      if (this.typeNo === 'unit') {
        url = 'template/applyUnit/queryPageByCondition'
      }
      if (this.typeNo === 'unitType') {
        url = 'template/applyUnitType/queryPageByCondition'
      }
      if (this.typeNo === 'variety') {
        url = 'category/applyPlantVariety/queryPageByCondition'
      }
      if (this.typeNo === 'category') {
        url = 'category/applyPlantType/queryPageByCondition'
      }
      if (this.typeNo === 'material') {
        url = 'template/applyMaterial/queryPageByCondition'
      }
      if (this.typeNo === 'materialType') {
        url = 'template/applyMaterialType/queryPageByCondition'
      }
      const { data: mes } = await Axios({
        method: "post",
        url: this.$webSerUrlPro + url,
        headers: {
          'databaseName': this.databaseName
        },
        data: params
      })
      // zhreq.getList(params).then(response => {
      //   let mes = response.data
      // console.log(mes)
      if (mes.code === 1) {
        this.ExamineTable = mes.data.content || []
        this.totalSize = mes.data.totalElements
        this.loading = false
        this.resetActionBar()
      } else {
        this.$message.warning("获取表格失败")
      }
      // })
    },
    async handlecheck(e) {
      let params = {}
      let url = ''
      if (this.typeNo === 'unit') {
        url = 'template/applyUnit/examine'
        params = {
          applyUnitNo: e.applyUnitNo,
          applyStatus: 0,
          organizationNo: e.organizationNo
        }
      }
      if (this.typeNo === 'unitType') {
        url = 'template/applyUnitType/examine'
        params = {
          applyUnitTypeNo: e.applyUnitTypeNo,
          applyStatus: 0,
          organizationNo: e.organizationNo
        }
      }
      if (this.typeNo === 'variety') {
        url = 'category/applyPlantVariety/examine'
        params = {
          applyPlantVarietyNo: e.applyPlantVarietyNo,
          applyStatus: 0,
          organizationNo: e.organizationNo
        }
      }
      if (this.typeNo === 'category') {
        url = 'category/applyPlantType/examine'
        params = {
          applyPlantTypeNo: e.applyPlantTypeNo,
          applyStatus: 0,
          organizationNo: e.organizationNo
        }
      }
      if (this.typeNo === 'material') {
        url = 'template/applyMaterial/examine'
        params = {
          applyMaterialNo: e.applyMaterialNo,
          applyStatus: 0,
          organizationNo: e.organizationNo
        }
      }
      if (this.typeNo === 'materialType') {
        url = 'template/applyMaterialType/examine'
        params = {
          applyMaterialTypeNo: e.applyMaterialTypeNo,
          applyStatus: 0,
          organizationNo: e.organizationNo
        }
      }
      const { data: mes } = await Axios({
        method: "post",
        url: this.$webSerUrlPro + url,
        headers: {
          'databaseName': this.databaseName
        },
        data: params
      })
      // zhreq.getList(params).then(response => {
      //   let mes = response.data
      // console.log(mes)
      if (mes.code === 1) {
        this.gettabledataList()
      } else {
        this.$message.warning("修改失败")
      }
    },
    handleclose(e) {
      this.dialogExamineFormVisible = true
      this.ExamineForm = e
    },
    async savemes(e) {
      let params = {
      }
      let url = ''
      if (this.typeNo === 'unit') {
        url = 'template/applyUnit/examine'
        params = {
          ...this.ExamineForm,
          applyStatus: 2,
          organizationNo: e.organizationNo
        }
      }
      if (this.typeNo === 'unitType') {
        url = 'template/applyUnitType/examine'
        params = {
          ...this.ExamineForm,
          applyStatus: 2,
          organizationNo: e.organizationNo
        }
      }
      if (this.typeNo === 'variety') {
        url = 'category/applyPlantVariety/examine'
        params = {
          ...this.ExamineForm,
          applyStatus: 2,
          organizationNo: e.organizationNo
        }
      }
      if (this.typeNo === 'category') {
        url = 'category/applyPlantType/examine'
        params = {
          ...this.ExamineForm,
          applyStatus: 2,
          organizationNo: e.organizationNo
        }
      }
      if (this.typeNo === 'material') {
        url = 'template/applyMaterial/examine'
        params = {
          ...this.ExamineForm,
          applyStatus: 2,
          organizationNo: e.organizationNo
        }
      }
      if (this.typeNo === 'materialType') {
        url = 'template/applyMaterialType/examine'
        params = {
          ...this.ExamineForm,
          applyStatus: 2,
          organizationNo: e.organizationNo
        }
      }
      const { data: mes } = await Axios({
        method: "post",
        url: this.$webSerUrlPro + url,
        headers: {
          'databaseName': this.databaseName
        },
        data: params
      })
      // zhreq.getList(params).then(response => {
      //   let mes = response.data
      // console.log(mes)
      if (mes.code === 1) {
        this.dialogExamineFormVisible = false
        this.gettabledataList()
      } else {
        this.$message.warning("修改失败")
      }
    },
    // 搜索
    search() {
      this.currentPage = 1;
      this.gettabledataList();
    },
    changePageSize(pageSize) {
      this.pageSize = pageSize;
      this.gettabledataList();
    },
    changeCurrentPage(currentPage) {
      this.currentPage = currentPage;
      this.gettabledataList();
    }
  }
};
</script>

<style>
</style>
